#include<bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int a[N],c[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        for(int i=1;i<=n;i++) cin >> a[i];
        for(int i=n;i>=1;i--){
            for(int j=i-1;j>=1;j--){
                if(a[i] == a[j]){
                    c[i] = a[i];
                }
            }
        }
        int sum = 0;
        for(int i=1;i<=n;i++){
            sum += c[i];
        }
        cout << sum << endl;
        memset(c,0,sizeof c);
        memset(a,0,sizeof a);
    }
    return 0;
}
